package com.forum.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.forum.annotation.IgnoreAuth;
import com.forum.entity.DataevaluationEntity;
import com.forum.entity.PgdInformationEntity;
import com.forum.service.PgdinformationService;
import com.forum.utils.MPUtil;
import com.forum.utils.PageUtils;
import com.forum.utils.R;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/Pgdinformation")
@Api(tags = "相关资料")
@Slf4j
public class PgdinformationController {
    @Autowired
    private PgdinformationService pgdinformationService;

    @GetMapping("/list")
    @IgnoreAuth
    @SuppressWarnings("unchecked")
    public R list(@RequestParam Map<String , Object> params, PgdInformationEntity pgdInformationEntity
                , HttpServletRequest request){
        EntityWrapper<PgdInformationEntity> entityWrapper = new EntityWrapper<>();
        PageUtils pageUtils = pgdinformationService.queryPage(params,
                MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(entityWrapper, pgdInformationEntity), params), params));
        log.info("分页参数:{}",pageUtils);
        return R.ok().put("data",pageUtils);
    }

    @GetMapping("/detail/{id}")
    @IgnoreAuth
    public R detail(@PathVariable("id") Long id){
        PgdInformationEntity pgdInformationEntity = pgdinformationService.selectById(id);
        return R.ok().put("data",pgdInformationEntity);
    }

    @PostMapping("/update")
    @Transactional
    @IgnoreAuth
    public R update(@RequestBody PgdInformationEntity pgdInformationEntity, HttpServletRequest request){
        //整体更新状态
        pgdinformationService.updateById(pgdInformationEntity);
        return R.ok();
    }

    /*@PostMapping("/add")
    @IgnoreAuth
    public R add(@RequestBody PgdInformationEntity dataevaluationEntity,
                 HttpServletRequest request){
        dataevaluationEntity.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
        log.info("相关返回参数：{}",dataevaluationEntity);
        pgdinformationService.insert(dataevaluationEntity);
        return R.ok();
    }*/

}
